package com.itheima.ydd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.ydd.dto.SysRoleDtoUtil;
import com.itheima.ydd.dto.SysUserDto;
import com.itheima.ydd.entity.Result;
import com.itheima.ydd.entity.SysRole;
import com.itheima.ydd.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@Slf4j
@RequestMapping("/sys_role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    //添加
    @PostMapping("/add")
    public Result save(@RequestBody Map<String,Object> map) {
        return sysRoleService.addRole(map);
    }

    //根据id修改
    @PostMapping("/update")
    public Result update(@RequestBody SysRole sysRole) {
        log.info("修改信息:{}",sysRole);
        sysRoleService.updateById(sysRole);
        return new Result(0,"");
    }

    //角色列表-全部
    @GetMapping ("/allData")
    public Result findAll(){

        return new Result(0,"",sysRoleService.list());
    }

    /*     角色列表-分页
     * page  页码数
     * limit 每页数量
     * name   角色名称,支持模糊查询
     * */
    @GetMapping("/list")
    public Result list(String page,String limit,String name){
        return sysRoleService.findAll(name,page,limit);
    }

    //根据id查询
    @GetMapping("/rowInfo")
    public Result findById(String id){
        SysRoleDtoUtil sysRoleInfo = sysRoleService.getSysRoleInfo(id);
        return new Result(0,"",sysRoleInfo);
    }

    //根据id删除
    @GetMapping("/del")
    public Result deleteById(String id){
        return sysRoleService.deleteSysRole(id);
    }
}
